package com.example.mvvmtest.Repository

import androidx.lifecycle.LiveData
import com.example.mvvmtest.model.dao.UserDao
import com.example.mvvmtest.model.entity.User
import kotlinx.coroutines.flow.Flow

// 数据仓库
class UserRepository(private val userDao: UserDao) {

    // 用户注册
    suspend fun registerUser(user: User) = userDao.registerUser(user)

    // 验证账号是否已注册
    suspend fun checkIsRegister(id: String) = userDao.checkIsRegister(id)

    // 登录验证
    suspend fun checkLogin(id: String, password: String) = userDao.checkLogin(id, password)

    // 获取用户信息（Flow实时更新）
    fun getUserInfo(id: String): Flow<User?> = userDao.getUserInfo(id)

    // 更新密码
    suspend fun updatePassword(id: String, newPassword: String) =
        userDao.updatePassword(id, newPassword)

    // 更新年龄
    suspend fun updateAge(id: String, newAge: Int) = userDao.updateAge(id, newAge)

    // 更新职业
    suspend fun updateJob(id: String, newJob: String) = userDao.updateJob(id, newJob)
}